package org.rency.common.utils.security;

import java.math.BigInteger;
import java.util.Date;
import java.util.Random;

import org.apache.commons.lang.builder.ToStringBuilder;
import org.apache.commons.lang.builder.ToStringStyle;
import org.rency.common.utils.tool.StringUtil;

public class X509CertDomain {

	private String fileName;
	private String organizationName;
	private String organizationEmail;
	private String password;
	private String alias;
	private String certStorePath;

	private BigInteger serialNumber;
	private String countryCode = "ZH";
	private String commonName = "CN";
	private String cityName = "SH";
	private String provinceName = "SH";
	
	public X509CertDomain(){
		byte[] b = new byte[32];  
        Random random = new Random(new Date().getTime());  
  
        for (int i = 0; i < 32; i++) {  
            byte[] tmp = new byte[10];  
            random.nextBytes(tmp);  
            b[i] = tmp[random.nextInt(tmp.length - 1)];  
        }  
        this.serialNumber = new BigInteger(b);  
	}
	
	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public BigInteger getSerialNumber() {
		return serialNumber;
	}

	public void setSerialNumber(BigInteger serialNumber) {
		this.serialNumber = serialNumber;
	}

	public String getOrganizationName() {
		return organizationName;
	}

	public void setOrganizationName(String organizationName) {
		this.organizationName = StringUtil.capitalize(organizationName);
	}

	public String getOrganizationEmail() {
		return organizationEmail;
	}

	public void setOrganizationEmail(String organizationEmail) {
		this.organizationEmail = organizationEmail;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getAlias() {
		return alias;
	}

	public void setAlias(String alias) {
		this.alias = alias;
	}

	public String getCertStorePath() {
		return certStorePath;
	}

	public void setCertStorePath(String certStorePath) {
		this.certStorePath = certStorePath;
	}

	public String getCountryCode() {
		return countryCode;
	}

	public void setCountryCode(String countryCode) {
		this.countryCode = countryCode;
	}

	public String getCommonName() {
		return commonName;
	}

	public void setCommonName(String commonName) {
		this.commonName = commonName;
	}

	public String getCityName() {
		return cityName;
	}

	public void setCityName(String cityName) {
		this.cityName = cityName;
	}

	public String getProvinceName() {
		return provinceName;
	}

	public void setProvinceName(String provinceName) {
		this.provinceName = provinceName;
	}

	public String toString(){
		return ToStringBuilder.reflectionToString(this, ToStringStyle.SHORT_PREFIX_STYLE);
	}
	
}